package com.example.dirviesystem.repository;

import com.example.dirviesystem.entity.AdminInfo;
import com.example.dirviesystem.entity.CoachInform;
import com.example.dirviesystem.entity.CoachMessage;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDateTime;

public interface CoachMessageRe extends JpaRepository<CoachMessage, Long>, JpaSpecificationExecutor<CoachMessage> {


    @Query("SELECT ci FROM CoachMessage ci WHERE ci.coach.id = :coachId " +
            "AND (:startDate IS NULL OR ci.createTime >= :startDate) " +
            "AND (:endDate IS NULL OR ci.createTime <= :endDate)")
    Page<CoachMessage> findByCoachIdAndDateRange(
            @Param("coachId") Long coachId,
            @Param("startDate") LocalDateTime startDate,
            @Param("endDate") LocalDateTime endDate,
            Pageable pageable);
}
